package com.csw.android.doubanslidedemo.slide.view;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

public class MyRecyclerView extends RecyclerView {

    private int mY = 0;
    private int mX = 0;

    public MyRecyclerView(@NonNull Context context) {
        super(context);
        init();
    }

    public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        addOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                mX += dx;
                mY += dy;
            }
        });
    }

    public int getScrollY2() {
        return mY;
    }

    public int getScrollX2() {
        return mX;
    }

    @Override
    public void scrollTo(int x, int y) {
        scrollBy(x - mX, y - mY);
    }
}
